/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       game_time.h

	$Header: /game/game_time.h $

	$NoKeywords: $

 ************************************************************************/
#ifndef GAME_TIME_H_INCLUDED
#define GAME_TIME_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "sized_int_types.h"

// Return the current time in milliseconds
t_uint32 get_time();
void     sleep_for( t_uint32 delay );

// Return the difference in milliseconds between 'stop' and 'start'
// Note: This fails if the difference is > 25 days and there is no 
//       way to check for this.
inline long elapsed_time( t_uint32 stop, t_uint32 start )
{
	return long( stop - start );
}

// Return the number of milliseconds that have elapsed since 'time'
// Note: This fails if the difference is > 25 days and there is no 
//       way to check for this.
inline long elapsed_time( t_uint32 start )
{
	return elapsed_time( get_time(), start );
}

// report if time has elapsed; if so, update start time.  Skips frames
// at no faster than double speed if several need to be skipped.
inline bool time_has_elapsed( t_uint32& start, int delay )
{
	t_uint32 now = get_time();

	if (elapsed_time( now, start ) < delay )
		return false;

	int half_delay = delay >> 1;

	start += delay;
	if (elapsed_time( now, start ) >= half_delay)
		start = now - half_delay;
	return true;
}

#endif // GAME_TIME_H_INCLUDED